import request from '@/utils/requset'

export const userRegisterService = ({ username, password, repassword }) => {
  const res = request({
    method: 'post',
    url: '/api/reg',
    data: {
      username,
      password,
      repassword,
    },
  })
  return res
}

export const userLoginService = ({ username, password }) => {
  return request({
    method: 'post',
    data: {
      username,
      password,
    },
    url: '/api/login',
  })
}
// 获取用户的基本信息
export const userGetInfoService = () => request.get('/my/userinfo')

// 修改用户基本信息
export const userUpdateInfoService = (userInfo) => {
  request({
    url: '/my/userinfo',
    method: 'PUT',
    data: userInfo,
  })
}
// 更新用户头像
export const userUpdateAvatarService = (avatar) => {
  request({
    url: '/my/update/avatar',
    method: 'patch',
    data: { avatar: avatar },
    headers: {
      'Content-Type': 'application/json',
    },
  })
}
// 更新用户密码
export const userUpdatePasswordService = ({ oldPwd, newPwd, rePwd }) => {
  request({
    method: 'patch',
    url: '/my/updatepwd',
    data: {
      oldPwd,
      newPwd,
      rePwd,
    },
  })
}
